'''
车辆管理相关页面测试
'''

from Lib.base.page_object.car_manager.car_add import CarAdd
from Lib.base.page_object.car_manager.car_list import CarList
from selenium.webdriver.common.by import By
import allure
import os
from Lib.common.assert_class import AssertClass
import pytest


@pytest.fixture(scope='class', autouse=True)
@pytest.mark.usefixtures('login')
def set_cls(login):
    TestCar.car = CarAdd(login)
    TestCar.car_list = CarList(login)
    TestCar.assert_class = AssertClass(login)


@allure.feature('车辆管理页面测试')
class TestCar:

    @allure.title("新建车辆")
    def test_01_create_car(self, login):
        '''
        新建一个车辆
        :return:
        '''
        self.car.car_add()
        # 设置断言
        assert_args = (By.XPATH, '//p[text()="创建成功！"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='创建成功', context='创建车辆')

    @allure.title('查看车辆列表')
    def test_02_car_list(self):
        '''
        查询车辆
        :return:
        '''
        self.car_list.car_list()
        # 设置断言
        assert_args = (By.XPATH, '//table[@class="rz-table__body"]//tr[1]/td[1]/div')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data='沪TEST01', context="查询车辆列表")

    @allure.title('搜索车辆并查看详情')
    def test_03_car_search_detail(self):
        '''
        搜索车辆并查看详情
        :return:
        '''
        self.car_list.car_search_detail()
        # 设置断言
        assert_args = (By.XPATH, '//span[text()="查看车辆详情"]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data="查看车辆详情", context="查询车辆详情")

    @allure.title("搜索车辆并编辑")
    def test_04_car_search_update(self):
        '''
        搜索车辆并编辑
        :return:
        '''
        self.car_list.car_search_update()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "更新成功")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data="更新成功", context="修改车辆")

    @allure.title("搜索车辆并删除")
    def test_05_car_search_delete(self):
        '''
        搜索车辆并并删除
        :return:
        '''
        self.car_list.car_detail_delete()
        # 设置断言
        assert_args = (By.XPATH, '//p[contains(text(), "暂无数据")]')
        self.assert_class.make_assert_by_text(args=assert_args, assert_data="暂无数据", context="删除车辆")


if __name__ == '__main__':
    pytest.main(['-v', './car_test.py', '--alluredir', '../result', '--clean-alluredir'])
    os.system(r'copy ..\config\environment.properties ..\result\environment.properties')
    os.system('allure generate  ../result -o ../report/ --clean')
